import { InputQuestion, QuestionBase, SelectQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { changeByte } from '@/utils/common';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '名称',
        value: null,
        state: {
          name: 'searchName'
        }
      })
    ];
    return questions;
  }
  getTargetQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'target',
        label: '文件',
        required: true,
        prompt: '请选择一个目标文件夹',
        value: null,
        state: {
          name: 'targetName'
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'key',
        value: null,
        type: 'slot',
        columns: { width: 60 },
        state: {
          slotName: 'fileImg'
        }
      }),
      new TextTable({
        key: 'name',
        value: '文件名称',
        type: 'slot',
        state: {
          slotName: 'fileName'
        },
        columns: {
          width: 350,
          sorter: (a, b) => {
            return a.name.localeCompare(b.name);
          }
        }
      }),
      new TextTable({
        key: 'size',
        value: '大小',
        type: 'slot',
        state: {
          slotName: 'size'
        },
        columns: {
          sorter: (a, b) => {
            return b.size - a.size;
          }
        }
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人',
        type: 'slot',
        state: {
          slotName: 'modifier'
        },
        columns: {
          sorter: (a, b) => {
            return a.modifierName.localeCompare(b.modifierName);
          }
        }
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间',
        type: 'slot',
        state: {
          slotName: 'updateTime'
        },
        columns: {
          sorter: (a, b) => {
            return Date.parse(a.modifiedTime) - Date.parse(b.modifiedTime);
          }
        }
      })
    ];
    return tables;
  }
}
export default new HomeService();
